﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Utilities;

namespace MaHoaUngDung
{
    public partial class EncryptFrm : DevComponents.DotNetBar.Office2007Form
    {
        public SymmetricAlgorithm EncryptionAlgorithm { get; set; }
        public User Receiver { get; set; }
        public PaddingMode PaddingMode { get; set; }
        public CipherMode CipherMode { get; set; }

        public EncryptFrm()
        {
            InitializeComponent();
            cbbReceiver.Items.AddRange(Program.ListUser.Users);

            cbbAlgo.SelectedIndex = 0;
            cbbPadding.SelectedIndex = 0;
            cbbCipher.SelectedIndex = 0;
            cbbReceiver.SelectedIndex = 0;

            EncryptionAlgorithm = new DESCryptoServiceProvider();
            PaddingMode = PaddingMode.None;
            CipherMode = CipherMode.CBC;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            switch (cbbAlgo.SelectedIndex)
            {
                case 0:
                    EncryptionAlgorithm = new DESCryptoServiceProvider();
                    break;
                case 1:
                    EncryptionAlgorithm = new TripleDESCryptoServiceProvider();
                    break;
                case 2:
                    EncryptionAlgorithm = new RC2CryptoServiceProvider();
                    break;
                case 3:
                    EncryptionAlgorithm = new RijndaelManaged();
                    break;
            }

            switch (cbbPadding.SelectedIndex)
            {
                case 0:
                    PaddingMode = PaddingMode.None;
                    break;
                case 1:
                    PaddingMode = PaddingMode.PKCS7;
                    break;
                case 2:
                    PaddingMode = PaddingMode.Zeros;
                    break;
                case 3:
                    PaddingMode = PaddingMode.ANSIX923;
                    break;
                case 4:
                    PaddingMode = PaddingMode.ISO10126;
                    break;
            }

            switch (cbbCipher.SelectedIndex)
            {
                case 0:
                    CipherMode = CipherMode.CBC;
                    break;
                case 1:
                    CipherMode = CipherMode.ECB;
                    break;
                case 2:
                    CipherMode = CipherMode.OFB;
                    break;
                case 3:
                    CipherMode = CipherMode.CFB;
                    break;
                case 4:
                    CipherMode = CipherMode.CTS;
                    break;
            }

            Receiver = cbbReceiver.SelectedItem as User;
            DialogResult = DialogResult.OK;
            this.Close();
        }
    }
}
